package com.lwei.ljpro.dto;

import com.fasterxml.jackson.databind.util.JSONPObject;
import com.fasterxml.jackson.databind.util.JSONWrappedObject;
import com.lwei.ljpro.emun.ProcessResult;
import com.lwei.ljpro.entry.BaseEntry;

import java.util.List;

/**
 * 消息对象
 */
public class Message<T> {

    private int code;
    private String msg;
    private int count = 0;
    private List<T> data;
    private String ext;
    private BaseEntry queryDto;

    public Message() {
    }

    public static Message instance(ProcessResult code){
        return new Message(code.getCode(), code.getMsg());
    }

    public static Message instance(ProcessResult code, String msg){
        return new Message(code.getCode(), msg);
    }

    private Message(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Message(ProcessResult code, String msg, List<T> data) {
        this.code = code.getCode();
        this.msg = msg;
        if(data.size() > 0){
            this.count = data.size();
        }
        this.data = data;
    }

    public Message(ProcessResult code, List<T> data) {
        this.code = code.getCode();
        this.msg = code.getMsg();
        if(data.size() > 0){
            this.count = data.size();
        }
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public BaseEntry getQueryDto() {
        return queryDto;
    }

    public void setQueryDto(BaseEntry queryDto) {
        this.queryDto = queryDto;
    }

    public String getExt() {
        return ext;
    }

    public void setExt(String ext) {
        this.ext = ext;
    }
}
